package com.example.threadSimple;

import java.util.concurrent.TimeUnit;

/**
 * @Author: Ah Nan
 * @Description: ThreadLocal实例
 * @Date: 16:24 2020/6/28
 */
public class ThreadLocalSimple {

    static ThreadLocal<PaymentModel> tl = new ThreadLocal<>();

    public static void main(String[] args) {
        new Thread(()->{
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(tl.get());
        }).start();

        new Thread(()->{
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            tl.set(new PaymentModel());
        }).start();
    }
}

